package com.tanhua.app.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.api.service.BlackListApi;
import com.tanhua.app.Interceptor.UserHolder;
import com.tanhua.model.pojo.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class BlackListService {

    @DubboReference
    private BlackListApi blackListApi;

    /**
     * 查询用户黑名单的数据
     * @return
     */
    public PageResult<UserInfo> findBlackPage(Integer page, Integer pagesize) {

        // 获取当前用户Id
        Long userId = UserHolder.getUserId();

        // 创建分页对象，根据userid查询黑名单的用户id，然后根据用户id查询对应的用户详情数据
        Page<UserInfo> pageInfo = new Page<>(page, pagesize);

        // 根据用户id查询对应的黑名单数据
        pageInfo = blackListApi.findBlackPage(pageInfo, userId);

        PageResult<UserInfo> pageResult =
                new PageResult<>(page, pagesize, pageInfo.getTotal(), pageInfo.getRecords());

        return pageResult;
    }

    /**
     * 根据用户id删除黑名单数据
     * @param uid
     */
    public void update(Long uid) {

        // 1. 获取当前用户id
        Long userId = UserHolder.getUserId();

        // 2. 执行方法
        blackListApi.update(uid, userId);

    }
}
